package com.yuelao.currentlimit;

import com.google.common.util.concurrent.RateLimiter;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Description
 *
 * @author fengliye
 * @version v1.0
 * @date 2019/03/20 14:47
 * @modify detail
 * 版本       修改人        修改时间      修改内容描述
 * ---------------------------------------------
 * <p>
 * ---------------------------------------------
 */
public class LimitTest {
    private int permitsPerSecond = 10; // 每秒10个许可
    private int threadNum = 100;

    public static void main(String[] args) {
        new LimitTest().call();
    }

    private void call() {
        ExecutorService executor = Executors.newFixedThreadPool(threadNum);
        final RateLimiter rateLimiter = RateLimiter.create(permitsPerSecond);
        for (int i = 0; i < threadNum; i++) {
            executor.execute(new CurrentLimit(rateLimiter));
        }
        executor.shutdown();
    }

}
